#ifndef __SENWORDPRO__
#define __SENWORDPRO__

#define USE_REGEXP

#include <string>
#include <vector>
#include "senwordtrie.h"
#include "re2/re2.h"
using namespace std;


typedef struct CharsetDetect 
{
    enum ByteNums{ONE=1, TWO, THREE, FOUR, FIVE, SIX};

    CharsetDetect(unsigned char l, unsigned char h, unsigned int n)
    {
        uLower = l;
        uHigher = h;
        nBytes = n;
    }

    unsigned char uLower;
    unsigned char uHigher;
    unsigned int nBytes;
}CCharsetDetect;


class CSenWordPro
{
public:
	CSenWordPro(){}

	~CSenWordPro(){}

	int init(const char* szCfgFile);

	int querySenWord(const char * srcContent, char **szRetSenWord) const;

    int querySenWordRegexp(const char * srcContent);

    int queryNickName(const char * srcContent);

    int replaceSenWord(char * srcContent);

    int GetStringWidth(const char* szSrc);

    int getRegexp(string & strRegexp);
    int getRegexpEmbed(string & strRegexp);

private:
	int insertSenWord( const char * src, unsigned int iuLen );

    int insertSenWord2( const char * src, unsigned int iuLen );

	string& TrimLeft(string& str, const char* pszTrim=" \t\r\n");

	string& TrimRight(string& str, const char* pszTrim=" \t\r\n");

    //Regexp
    int initUtf8Range();
    int insertSenWordRegexp( const char * src, unsigned int iuLen );
    unsigned int getBytes(unsigned char uByte);
    int addRegexpPattern(string & strSenWord, bool bIsEmbed=false);
    int queryIsEmbedWord(string& src, string& strKey);
    int realSenWordProcess(char * srcContent, bool bIsQuery=false);

private:
	SenWordTrie m_swt;  //not embed word
	SenWordTrie m_swtEmbed;  //embed word

    //string Regexp
    string m_strRegPattern;
    string m_strRegPatternEmbed;
    vector<CCharsetDetect> m_vCharDec;
    bool m_bRegexpSet;
    RE2::Options m_re2opt;//RE2 options
};


#endif 
